<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\report;

use app\enum\ReportRecordEnum;
use app\model\ReportRecordModel;
use app\service\BaseService;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class ReportService extends BaseService
{
    /**
     * 获取当天报表列表数据.
     *
     * @param mixed $week 本周第几天
     * @return array|Collection|ReportRecordModel[]
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public static function getReportWeekList($week = null)
    {
        $query = (new ReportRecordModel())->where('is_send', ReportRecordModel::SEND_YES);
        if (! is_null($week)) {
            // TODO whereLike查询优化.
            $query->whereLike('send_date', '%' . $week . '%')->where('dimension', ReportRecordEnum::REPORT_DIMENSION_ACCOUNT);
        }
        return $query->select();
    }
}
